package com.lvy.hczn.transmit.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lvy.hczn.front.common.constant.Constants;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.system.domain.business.GoodsBoxSpec;
import com.lvy.hczn.front.system.domain.business.Warehouse;
import com.lvy.hczn.front.system.service.GoodsBoxSpecService;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.transmit.domain.dto.cteck.ContainerInfo;
import com.lvy.hczn.transmit.service.TGoodsBoxSpecService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/api/dt/box/")
@Slf4j
public class TGoodsBoxSpecController {

    @Autowired
    private TGoodsBoxSpecService tGoodsBoxSpecService;

    /**
     * 货箱规格同步
     *
     * @param info
     * @return
     */
    @ApiOperation(value = "货箱规格同步", notes = "货箱规格同步")
    @PostMapping("spec")
    @ResponseBody
    public AjaxResult syncBoxSpecFromPlatForm(HttpServletRequest request, @RequestBody ParamInfo<ContainerInfo> info) {
        try {
            tGoodsBoxSpecService.syncBoxSpecFromPlatForm(info);
            return AjaxResult.success();
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("spec同步异常：{}", e);
                return AjaxResult.error("系统异常");
            }
        }
    }


    @ApiOperation(value = "货箱规格列表", notes = "货箱规格列表")
    @PostMapping("spec/list")
    @ResponseBody
    public AjaxResult specList(HttpServletRequest request, @RequestBody ParamInfo<GoodsBoxSpec> info) {
        try {
            List<GoodsBoxSpec> list = tGoodsBoxSpecService.specList(info);
            return AjaxResult.success(list);
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("specList同步异常：{}", e);
                return AjaxResult.error("系统异常");
            }
        }
    }
}
